fix(rivetkit): prevent sleep races during disconnect and db work#4644
fix(rivetkit): prevent sleep races during disconnect and db work#4644NathanFlurry wants to merge 1 commit intofix/isolate-engine-envoysfrom
Conversation
Code ReviewOverviewThis PR fixes a race condition in the actor sleep lifecycle where an actor could enter sleep prematurely when a connection is being disconnected but the onDisconnect callback has not yet completed. Two targeted changes:
Race Condition Being FixedBefore this fix:
The fix ensures that after incrementing pendingDisconnectCount, the timer is immediately reset so the next canSleep() evaluation returns CanSleep.ActiveDisconnectCallbacks. The guard in the setTimeout callback provides defense-in-depth for any remaining timing gaps. Code QualityStrengths:
Suggestions:
VerdictThe logic is correct and the fix is well-targeted. No functional concerns. The main suggestion is a short comment on the timer guard in mod.ts to document the intent. |
7825238 to
f6957bf
Compare
f6957bf to
8584a4e
Compare
b2d071c to
3a17032
Compare

Description
Please include a summary of the changes and the related issue. Please also include relevant motivation and context.
Type of change
How Has This Been Tested?
Please describe the tests that you ran to verify your changes.
Checklist: